package com.gh.filetest;

import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

public class SubStringTest {

    //截取文件后缀
    @Test
    public void t2(){
        String s1  = "E:\\123.jpg";
        /*String s2  = "E:\\file.docx";*/
        String susname = s1.substring(s1.lastIndexOf("."));
        System.out.println(susname);
    }


    //截取前缀
    @Test
    public void t3(){
        String s1  = "E:\\123.jpg";
        System.out.println(s1);
        System.out.println("\\");
        String[] temp = s1.split("\\\\");
        String path = temp[0];
        for(String temp2:temp){
            System.out.println(temp2+"\\");
        }
        System.out.println(path);
    }


    //uuid生成随随机码拼接字符串
    @Test
    public void t4(){
        String s1  = "E:\\123.jpg";
        String str1 = s1.substring(s1.lastIndexOf("."));
        String strnew = UUID.randomUUID().toString()+str1;
        System.out.println(strnew);//类似：a13daf17-8ba3-46be-91a8-d931340e704d.jpg
    }

    //创建文件夹
    @Test
    public void t5(){
        File s1  = new File("D:\\JAVA\\Web\\reiji\\loadfile\\img\\");
        File s2  = new File("D:/JAVA/Web/reiji/loadfile/img2/");
        //mkdirs多个或者多层文件
        s1.mkdirs();
        s2.mkdir();
    }

}
